﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 


namespace MaxStudio.Concrete.Server.Service
{
    public class RPTMaterialCostService : ServiceHandle, IRPTMaterialCost
    {
        #region IRPTMaterialCost Members

        public OperationResult<List<tb_RPT_MaterialCost>> GetAllMaterialCost()
        {
            OperationResult<List<tb_RPT_MaterialCost>> result = new OperationResult<List<tb_RPT_MaterialCost>>();
            List<tb_RPT_MaterialCost> list = new List<tb_RPT_MaterialCost>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllMaterialCost();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_MaterialCost>> GetMaterialCostByContition(string strProdCode, string strSlump)
        {
            OperationResult<List<tb_RPT_MaterialCost>> result = new OperationResult<List<tb_RPT_MaterialCost>>();
            List<tb_RPT_MaterialCost> list = new List<tb_RPT_MaterialCost>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetMaterialCostByContition(strProdCode, strSlump);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_MaterialCost> GetMaterialCostById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_MaterialCost> result = new OperationResult<tb_RPT_MaterialCost>();
            tb_RPT_MaterialCost materialCost;
            try
            {
                materialCost = dataContext.GetMaterialCostById(id);
                if (materialCost == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = materialCost;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_MaterialCost> CreateMaterialCost(tb_RPT_MaterialCost entity)
        {
            OperationResult<tb_RPT_MaterialCost> result = new OperationResult<tb_RPT_MaterialCost>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateMaterialCost(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_MaterialCost> ModifyMaterialCost(tb_RPT_MaterialCost entity)
        {
            OperationResult<tb_RPT_MaterialCost> result = new OperationResult<tb_RPT_MaterialCost>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyMaterialCost(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_MaterialCost> DeleteMaterialCost(tb_RPT_MaterialCost entity)
        {
            OperationResult<tb_RPT_MaterialCost> result = new OperationResult<tb_RPT_MaterialCost>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteMaterialCost(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
